package com.bawei.mall.product.controller;

import com.bawei.common.core.domain.R;
import com.bawei.common.core.web.controller.BaseController;
import com.bawei.mall.product.service.ICProductService;
import com.bawei.mall.product.domain.Po.Product;
import com.bawei.mall.product.domain.Vo.BrandVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @Author：liurui
 * @Package：com.bawei.mall.search.controller
 * @Project：mall_cloud
 * @name：UserProductController
 */
@RestController
@Log4j2
@RequestMapping("/home")
public class CProductController extends BaseController {
    @Autowired
    private ICProductService service;

    @GetMapping("/recommendProductList")
    public R<List<Product>> recommendProductList(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        List<Product> list=service.recommendProductList();
        return R.ok(list);
    }

    /**
     * 关键词搜索
     * @return
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @GetMapping("/keyWordSearch")
    public R<List<Product>> keyWordSearch(@RequestParam Integer pageNum, @RequestParam Integer pageSize,@RequestParam String keyWord){
        startPage();
        List<Product> list=service.keyWordSearch(keyWord);
        return R.ok(list);
    }

    /**
     * 关键词联想
     * @return
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @GetMapping("/association")
    public R<List<String>> association(@RequestParam String keyWord){
        List<String> list=service.association(keyWord);
        return R.ok(list);
    }

    @GetMapping("/content")
    public R<BrandVo> content() throws ExecutionException, InterruptedException {
        BrandVo brandVo=service.content();
        return R.ok(brandVo);
    }

    @GetMapping("/productList")
    public R<Map<String, Object>> productList(@RequestParam Integer brandId, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        List<Product> list=service.productList(brandId);
        Map<String, Object> data = new HashMap<>();
        data.put("list", list);

        return R.ok(data);
    }



}
